package com.tlsy.commerce.model.converter;

import com.tlsy.commerce.model_enum.RoleTypeEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author Tlsy
 * @version commerce 0.0.1
 * @date 2017/4/22  17:53
 */
@Converter
public class RoleTypeConverter implements AttributeConverter<RoleTypeEnum,String> {
    @Override
    public String convertToDatabaseColumn(RoleTypeEnum roleTypeEnum) {
        if(roleTypeEnum==null){
            return null;
        }
        return roleTypeEnum.value();
    }

    @Override
    public RoleTypeEnum convertToEntityAttribute(String type) {
        if(type==null){
            return null;
        }
        return RoleTypeEnum.fromValue(type);
    }
}
